<?php

use yii\db\Migration;

class m161208_085230_create_user extends Migration
{
    public function up()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=MyISAM';
        }

        $this->createTable('{{%user}}', [
            'id' => $this->primaryKey()->unsigned()->comment('自增id'),
            'username' => $this->string()->notNull()->unique()->comment('用户名'),
            'auth_key' => $this->string(32)->notNull()->comment('自动登录key'),
            'password_hash' => $this->string()->notNull()->comment('加密密码'),
            'password_reset_token' => $this->string()->defaultValue('')->comment('重置密码token'),
            'email' => $this->string()->notNull()->defaultValue('')->comment('邮箱'),
            'real_name' => $this->string()->defaultValue('')->comment('真实姓名'),
            'position' => $this->string()->defaultValue('')->comment('岗位'),
            'parent' => $this->string()->defaultValue('')->comment('所属父类'),
            'role_key' => $this->string()->defaultValue('')->comment('推广标识'),
            'role' => $this->smallInteger()->notNull()->defaultValue(10)->comment('角色标识'),
            'status' => $this->smallInteger()->notNull()->defaultValue(10)->comment('状态'),
            'created_at' => $this->integer()->notNull()->comment('创建时间'),
            'updated_at' => $this->integer()->notNull()->comment('更新时间'),
            'last_login_time' => $this->integer()->notNull()->comment('最后登录时间'),
            'deducted' => $this->decimal()->defaultValue(0)->comment('扣量百分比'),
        ], $tableOptions);
    }

    public function down()
    {
        $this->dropTable('{{%user}}');
    }
}
